package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author tangsy
 * @Description TODO
 * @date 2022/11/30 17:37
 * @Version 1.0
 */
@Slf4j
@Api(tags = "文件管理")
@RestController
@RequestMapping("/admin/product")
public class FileController {

    @Autowired
    FileService fileService;

    @SneakyThrows
    @ApiOperation("图片上传")
    @PostMapping("fileUpload")
    public Result upload(@RequestPart("file")MultipartFile file){
        String contentType = file.getContentType();
        String filename = file.getOriginalFilename();
        log.info("文件上传：文件名：{}，文件大小：{}，文件类型：{}",filename,file.getSize(),contentType);

        String path = fileService.upload(file);
        return Result.ok(path);
    }

}
